home *** CD-ROM | disk | FTP | other *** search
/ isnet Internet / Isnet Internet CD.iso / prog / hiz / 09 / 09.exe / adynware.exe / perl / lib / adynware / unique_scripts.pm < prev    next >
Encoding:
Perl POD Document  |  1999-12-28  |  5.5 KB  |  191 lines

  1. package unique_scripts;
  2. use strict;
  3. use diagnostics;
  4.  
  5. my @__all = ();
  6.  
  7.  
  8. sub create
  9. {
  10.         my($listFormsFirst, $frameGroupID, $frameSetURL) = @_;
  11.         my $x = unique_scripts->new($listFormsFirst, $frameGroupID, $frameSetURL);
  12.         if (scalar(@__all) < 10)
  13.         {
  14.                 push(@__all, \$x);
  15.         }
  16.         else
  17.         {
  18.                 my $oldestIndex = 0;
  19.                 my $y = $__all[0];
  20.                 my $oldestAge = $$y->{"age"};
  21.                                                  
  22.                 for (my $j = 1; $j < scalar(@__all); $j++)
  23.                 {
  24.                         $y = $__all[$j];
  25.                         if ($oldestAge < $$y->{"age"})
  26.                         {
  27.                                 $oldestIndex = $j;
  28.                                 $oldestAge = $$y->{"age"};
  29.                         }
  30.                 }
  31.                 $y = $__all[$oldestIndex];
  32.                 utility::Log("unique scripts create: ejected group " . $$y->{"frameGroupID"});
  33.                 $__all[$oldestIndex] = \$x;
  34.         }
  35.         utility::Log("unique scripts create: added group " . $x->{"frameGroupID"});
  36.         return \$x;
  37. }
  38.  
  39. sub findFrameGroup
  40. {
  41.         my($target, $removeMatch) = @_;
  42.         foreach my $x (@__all)
  43.         {
  44.                 if (defined $$x->matchTarget($target, $removeMatch))
  45.                 {
  46.                         utility::Log("unique scripts find frame group($target, $removeMatch): " . $$x->{"frameGroupID"}); #@@
  47.                         return $x;
  48.                 }
  49.         }
  50.         utility::Log("unique scripts find frame group($target, $removeMatch): nothing"); #@@
  51.         return undef;
  52. }
  53.  
  54. sub redirect
  55. {
  56.         my($oldURL, $newURL) = @_;
  57.                 
  58.         utility::Log("unique redirect:$oldURL, $newURL");
  59.         
  60.         my $x = findFrameGroup("http://$oldURL", 1);
  61.         return unless defined $x;
  62.         $$x->addFrame($newURL);
  63. }
  64.  
  65. sub replaceFrame
  66. {
  67.         my($frameGroupID, $documentID, $URL) = @_;
  68.         my $hit = 0;
  69.         foreach my $x (@__all)
  70.         {
  71.                 if (!$hit and $$x->getFrameGroupID()==$frameGroupID)
  72.                 {
  73.                         $hit = 1;
  74.                         $$x->free($documentID);
  75.                         $$x->addFrame($URL);
  76.                         $$x->adjustAge(-1);
  77.                 }
  78.                 else
  79.                 {
  80.                         $$x->adjustAge(1);
  81.                 }
  82.         }
  83.         utility::Log("unique scripts replace frame($frameGroupID, $documentID, $URL): nothing") unless $hit;
  84. }
  85.  
  86. sub addFrame
  87. {
  88.         my($self, $URL) = @_;
  89.         utility::Log("add frame to group " . $self->{"frameGroupID"} . ":$URL");#@@
  90.         $self->{$URL} = 1;
  91. }
  92.  
  93. sub adjustAge
  94. {
  95.         my($self, $change) = @_;
  96.         $self->{"age"} += $change;
  97.         utility::Log("adjust age for group " . $self->{"frameGroupID"} . ": " . $self->{"age"});#@@
  98. }
  99.  
  100. sub matchTarget
  101. {
  102.         my($self, $URL, $removeMatch) = @_;
  103.         return delete($self->{$URL}) if $removeMatch;
  104.         return $self->{$URL};
  105. }
  106.  
  107. sub getFrameGroupID
  108. {
  109.         my($self) = @_;
  110.         return $self->{"frameGroupID"};
  111. }
  112.  
  113. sub getIndex
  114. {
  115.         my($self, $documentID, $isLink) = @_;
  116.         my $index = 0;
  117.         my $uniqueAllocation = $self->{"allocation"};
  118.         if (!$isLink and defined $self->{"formFieldIndex"})
  119.         {
  120.                 for (; (25 >= $self->{"formFieldIndex"}); $self->{"formFieldIndex"}++)
  121.                 {
  122.                         if (!defined $$uniqueAllocation[$self->{"formFieldIndex"}] or !$$uniqueAllocation[$self->{"formFieldIndex"}])
  123.                         {
  124.                                 $index = $self->{"formFieldIndex"}++;
  125.                                 last;
  126.                         } 
  127.                 }
  128.         } 
  129.         if (!$index)
  130.         {
  131.                 while (defined $$uniqueAllocation[$self->{"index"}] and $$uniqueAllocation[$self->{"index"}])
  132.                 {
  133.                         $self->{"index"}++;
  134.                 } 
  135.                 $index = $self->{"index"}++;
  136.         }
  137.         $$uniqueAllocation[$index] = $documentID;
  138.         return $index;
  139. }
  140.  
  141. sub free
  142. {
  143.         my($self, $documentID) = @_;
  144.         my $uniqueAllocation = $self->{"allocation"};
  145.         for (my $j=1; $j < scalar(@$uniqueAllocation); $j++)
  146.         {
  147.                 if ($$uniqueAllocation[$j] == $documentID)
  148.                 {
  149.                         $$uniqueAllocation[$j] = 0;
  150.                         if (defined $self->{"formFieldIndex"} and ($j <= 25))
  151.                         {
  152.                                 $self->{"formFieldIndex"} = $j if ($j < $self->{"formFieldIndex"});
  153.                         }
  154.                         elsif ($j < $self->{"index"})
  155.                         {
  156.                                 $self->{"index"} = $j;
  157.                         } 
  158.                 }
  159.         }
  160. }
  161.  
  162.  
  163. sub new
  164. {
  165.         my $this = shift;
  166.         my $listFormsFirst = shift;
  167.         my $frameGroupID = shift;
  168.         my $frameSetURL = shift;
  169.         my $class = ref($this) || $this;
  170.         my $self = {};
  171.         
  172.         bless $self, $class;
  173.         
  174.         $self->{"age"} = 0;
  175.         $self->{"allocation"} = [];
  176.         $self->{"frameGroupID"} = $frameGroupID;
  177.         $self->{"frameSetURL"} = $frameSetURL;
  178.         if ($listFormsFirst)
  179.         {
  180.                 $self->{"index"} = 26;        # counter for generating superscripts for links
  181.                 $self->{"formFieldIndex"} = 1;    # counter for generating superscripts for form fields
  182.         }
  183.         else
  184.         {
  185.                 $self->{"index"} = 1;        # counter for generating superscripts for all items
  186.         }
  187.         return $self;
  188. }
  189.  
  190. 1;
  191.